<include file="Public/header" />
<script type="text/javascript">
function submit_delete_batch(type){
    /* 获取选中的项 */
    var items = '';
    $('.checkitem:checked').each(function(){
        items += this.value + ',';
    });
    if(items != '') {
        items = items.substr(0, (items.length - 1));
        submit_delete(items,type);
    }  
    else {
        alert('请选择要操作的对象');
    }
}
function submit_delete(id,type)
{
    if(confirm('确定进行该操作？')) 
	{ 
        $('#coupon_id').val(id);
        $('#list_form').submit();
    }
}
function ajax_set_recommend(stat,coupon_id)
{
	$.getJSON("{:U('Coupon/ajax_recommend')}?coupon_id="+coupon_id+"&stat="+stat, function(result){
		if(result.done){
			if(stat == 1){
				var stat_show = '是';
				var rechange_tip = '取消推荐';
				var new_rcstat = 0;
			}else{
				var stat_show = '否';
				var rechange_tip = '设为推荐';
				var new_rcstat = 1;
			}
			$('#re_stat_'+coupon_id).html(stat_show);
			$('a[re_change="'+coupon_id+'"]').html("["+rechange_tip+"]").attr("href","javascript:ajax_set_recommend("+new_rcstat+","+coupon_id+");");
        }else{
            alert('优惠券推荐状态修改失败');
        }
	});
}
</script>
<div class="page">
  <div class="fixed-bar">
    <div class="item-title">
      <h3>优惠券管理</h3>
      <ul class="tab-base">
        <li><a href="javascript:void(0);" class="current"><span>管理</span></a></li>
      </ul>
    </div>
  </div>
  <div class="fixed-empty"></div>
  <form method="get" name="formSearch">
    <table class="tb-type1 noborder search">
      <tbody>
        <tr>
          <td>
			  <select name='s_type'>
				<option value="coupon_name" <if condition="$search['s_type'] eq 'coupon_name'">selected</if>>优惠券名称</option>
				<option value="store_name" <if condition="$search['s_type'] eq 'store_name'">selected</if>>商铺名称</option>
			  </select>
          </td>
          <td><input type="text" value="{$search['s_content']}" name="s_content" class="txt" ></td>
          <td>审核状态：</td>
          <td>
			  <select name='s_audit'>
				<option value="" selected>全部</option>
				<option value="1" <if condition="$search['s_audit'] eq 1">selected</if>>待审核</option>
				<option value="2" <if condition="$search['s_audit'] eq 2">selected</if>>审核通过</option>
				<option value="3" <if condition="$search['s_audit'] eq 3">selected</if>>审核未通过</option>
			  </select>
          </td>
          <td><a href="javascript:document.formSearch.submit();" class="btn-search tooltip" title="查询">&nbsp;</a></td>
        </tr>
      </tbody>
    </table>
  </form>
  <!-- 操作说明 -->
  <table class="table tb-type2" id="prompt">
    <tbody>
      <tr class="space odd">
        <th colspan="12" class="nobg"><div class="title">
            <h5>操作提示</h5>
            <span class="arrow"></span></div></th>
      </tr>
      <tr>
        <td>
        	<ul>
            	<li>可以对优惠券进行删除和审核操作</li>
            	<li>优惠券列表显示优惠券名称、有效位、商铺名称、下载次数等信息</li>
            	<li>可以设置是否推荐到首页轮播广告下方进行展示（最多展示3个）</li>
         	</ul>
        </td>
      </tr>
    </tbody>
  </table>
  <form id="list_form" method='post' action="{:U('Coupon/coupon_del')}">
    <input id="coupon_id" name="coupon_id" type="hidden" />
    <table class="table tb-type2">
      <thead>
        <tr class="space">
          <th colspan="15" class="nobg">列表</th>
        </tr>
        <tr class="thead">
          <th class="w48"></th>
          <th>优惠券名称</th>
		  <th>有效期</th>
		  <th>商铺名称</th>
		  <th>下载次数</th>
		  <th>览浏次数</th>
		  <th>数量</th>
		  <th>审核</th>
		  <th class="w108">首页推荐</th>
          <th class="w200 align-center">操作</th>
        </tr>
      </thead>
      <tbody>
        <notempty name="list">
        <volist name="list" id="val">
        <tr class="hover edit">
		  <td><input type="checkbox" value="{$val['coupon_id']}" class="checkitem"></td>
          <td><a href="" target="_blank">{$val['coupon_name']}</a></td>
		  <td>{$val['coupon_start_time']|date='Y-m-d',###}~{$val['coupon_end_time']|date='Y-m-d',###}</td>
		  <td><a href="" target="_blank">{$val['store_name']}</a></td>
		  <td>{$val['download_count']}</td>
		  <td>{$val['view_count']}</td>
		  <td>{$val['limit']}</td>
		  <td>
          <if condition="$val['audit'] eq 1">待审核
          <elseif condition="$val['audit'] eq 2"/>
          <else/>审核不通过
          </if>
          </td>
		  <td>
          <span id="re_stat_{$val['coupon_id']}">{$val['is_recommend']?'是':'否'}</span>
          <a re_change="{$val['coupon_id']}" class="marginleft" href="javascript:ajax_set_recommend({$val['is_recommend']==0?'1':'0'},{$val['coupon_id']});">[{$val['is_recommend']?'取消推荐':'设为推荐'}]</a>
          </td>
		  <td class='align-center'>
		  <if condition="$val['audit'] eq 1">
		  <a href="{:U('Coupon/audit',array('coupon_id'=>$val['coupon_id']))}">审核</a>
		  <else/>
		  <span style="color:#ccc">审核</span>
		  </if>
		  &nbsp;|&nbsp;<a href='javascript:if(confirm("确定要删除？"))window.location="{:U('Coupon/coupon_del',array('coupon_id'=>$val['coupon_id']))}";'>删除</a></td>
        </tr>
        </volist>
        <else/>
        <tr class="no_data">
          <td colspan="10">暂无记录</td>
        </tr>
        </notempty>
      </tbody>
      <notempty name="list">
      <tfoot>
        <tr class="tfoot">
          <td>
          	<input type="checkbox" class="checkall" id="checkall_1">
          </td>
          <td id="batchAction" colspan="15">
          	<span class="all_checkbox">
            	<label for="checkall_1">全选</label>
            	&nbsp;<a href="javascript:void(0)" class="btn" onclick="submit_delete_batch('del');"><span>删除</span></a>
            </span>
            <div class="pagination">{$page_show}</div>
        </tr>
      </tfoot>
     </notempty>
    </table>
  </form>
</div>
<include file="Public/footer" />